package com.jaux.hotel.controller;

import com.jaux.hotel.common.Result;
import com.jaux.hotel.pojo.Course;
import com.jaux.hotel.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author JAUX
 */

@Api(tags = "课程管理接口")
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 通过课程id查询信息
     * @param courseId 课程id
     * @return 课程信息
     */
    @GetMapping("/select/{courseId}")
    @ApiOperation(value = "通过课程id查询课程信息", notes = "通过课程id查询课程信息")
    public Result<Course> selectById(@PathVariable("courseId") String courseId){
        return Result.success(courseService.getById(courseId), "查询成功");
    }

    /**
     * 通过课程名查询课程信息
     * @param courseName 课程名
     * @return 课程信息
     */
    @GetMapping("/info")
    @ApiOperation(value = "通过课程名查询", notes = "通过课程名查询")
    public Result<List<Course>> selectByInfo(String courseName){
        return Result.success(courseService.selectByInfo(courseName), "查询成功");
    }

    /**
     * 添加课程
     * @param course 课程对象
     * @return 显示添加结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加课程", notes = "添加课程")
    public Result<String> addCourse(@RequestBody Course course){
        return Result.success(null,courseService.insertCourse(course));
    }
}
